package org.ls.petclinic.dao.impl;

import org.ls.petclinic.dao.OwnerDao;
import org.ls.petclinic.pojo.Owner;

import java.util.List;

/**
 * @author 浪矢先生
 * @description
 * @create 2022-12-05 21:58
 */
public class OwnerDaoImpl extends BaseDao implements OwnerDao {
    @Override
    public List<Owner> getAll() {
        return queryForList(Owner.class,"select * from owner ");
    }

    @Override
    public List<Owner> getByName(String name) {
        return queryForList(Owner.class,"select * from owner where name like ?","%"+name+"%");
    }

    @Override
    public Owner getById(Long id) {

        return queryForOne(Owner.class,"select * from owner where id=?",id);
    }

    @Override
    public int add(Owner owner) {

        return insert("insert into owner(name,address,city,phone) values(?,?,?,?)",owner.getName(),owner.getAddress(),owner.getCity(),owner.getPhone());
    }

    @Override
    public int update(Owner owner) {

        return update(" UPDATE owner SET name=?, address=?,city=?,phone=? WHERE id=?",owner.getName(),owner.getAddress()
        ,owner.getCity(),owner.getPhone(),owner.getId());
    }
}
